<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.ArrayList, db.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<!-- Icons for Web App
<link rel="apple-touch-icon" sizes="114x114" href="images/nav/index@2x.png">
<link rel="apple-touch-startup-image" href="images/splash/splash-screen.png" media="screen and (max-device-width: 320px)" />
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/splash/splash-screen@2x.png" />
-->
<title>Frontera Pesos</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<link href="styles/type.css" rel="stylesheet" type="text/css">
<link href="styles/buttons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)"	type="text/css" href="styles/highdpi.css" />

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/highdpi.js"></script>
<script type="text/javascript" src="scripts/custom.js"></script>
<!-- utility js -->
<script type="text/javascript" src="../scripts/fronteraWebUtility.js"></script>
<% // DBHelper helper = new DBHelper();
	Coupons coupons = new Coupons();
	FormatAndValidation fav = new FormatAndValidation();
    String serverName =  request.getRemoteHost();
	String _errorMessage = "";
	String _userName = "";
	String _loginID = "";
	String displayRewardsSec = "none";
	int storeCkInId = 0;
	int admin = 0;
	int server = 0;
	int checkID = 0;
	String showAdminBtn = "none";
	String showServerBtn = "none";
	
	Cookie[] cookies = request.getCookies();
	ArrayList<UserData> userInfo =  new ArrayList<UserData>();
	ArrayList<Coupons> couponInfo =  new ArrayList<Coupons>();
	ArrayList<Campaign> campaignInfo =  new ArrayList<Campaign>();
	ArrayList<StoreLocation> storeInfo =  new ArrayList<StoreLocation>();
	int id = -1;
	 Enumeration<String> enumeration = request.getParameterNames();
	 while (enumeration.hasMoreElements()) {
	     String parameterName = (String) enumeration.nextElement();
	     	     
	     System.out.println("Parameter = " + parameterName + " val = " + request.getParameter(parameterName));
	     
	 }
	
	if(request.getParameter("aID") != null)
	{
		id = Integer.parseInt(request.getParameter("aID"));
		if(session.getAttribute("campaignInfo") != null)
		 {
		 	Object t = session.getAttribute("campaignInfo");
		 	campaignInfo = (ArrayList<Campaign>) t;
		 	
		 	
		 	
		 }	
	}
	if(session.getAttribute("adminRights") != null)
	{
		   
		    Object g =  session.getAttribute("adminRights");
		    admin = Integer.parseInt(g.toString());
		    if(admin == 1)
			{
		    	 showAdminBtn = "inline";
			}
		   
		   
		    System.out.println(" showAdminBtn ==  " + admin);
	}
	if(session.getAttribute("serverRights") != null)
	{
		   
		    Object g =  session.getAttribute("serverRights");
		    server = Integer.parseInt(g.toString());
		    if(server == 1)
			{
		    	showServerBtn = "inline";
			}
		    
		    System.out.println(" showServerBtn ==  " + server);
	}


	
	
 	%>
 <script>
 function submitRule(formName)
 {
 	document.getElementById(formName).submit();
 }
function formSubmitCampaign()
{
document.getElementById("addcampaign").submit();
}
function formSubmitCustomer()
{
document.getElementById("editcustomer").submit();
}
function formSubmitBirthday()
{
document.getElementById("birthday").submit();
}
</script>


</head>
<body>


 	<%
	if(campaignInfo.size() != 0)
	{
	 for(int i = 0; i < campaignInfo.size(); i++) {
			System.out.println(" campaignInfo " + campaignInfo.get(i).getCampaignName());
	 }
	 
	 couponInfo = coupons.getAllCouponsinfo();
	 	
 	 for(int i = 0; i < couponInfo.size(); i++) {
 			System.out.println(" couponInfo " + couponInfo.get(i).getCouponName());
 	 }
	}
	%>

<% 

if(session.getAttribute("userInfo") != null)
	{
		Object t = session.getAttribute("userInfo");
		userInfo = (ArrayList<UserData>) t;
		 for(int i = 0; i < userInfo.size(); i++) {
				System.out.println(" userdata " + userInfo.get(i).getPhoneNumber());
		 }
	} 
if(session.getAttribute("checkinID") != null)
{
	   
	    Object g =  session.getAttribute("checkinID");
	    checkID = Integer.parseInt(g.toString());
	    
}

if(session.getAttribute("storeInfo") != null)
	{
		Object t = session.getAttribute("storeInfo");
		storeInfo = (ArrayList<StoreLocation>) t;
		 for(int i = 0; i < storeInfo.size(); i++) {
				System.out.println(" storeInfo " + storeInfo.get(i).getStoreName());
		 }
	}

if(session.getAttribute("displayRewardsSec") != null)
{
	   
	    Object g =  session.getAttribute("displayRewardsSec");
	    displayRewardsSec = g.toString();
	    
}
if(session.getAttribute("storeCkInId") != null)
{
	   
	    Object g =  session.getAttribute("storeCkInId");
	    storeCkInId = Integer.parseInt(g.toString());
	    
	    System.out.println(" storeCkInId ==  " + storeCkInId);
}

if(session.getAttribute("adminRights") != null)
{
	   
	    Object g =  session.getAttribute("adminRights");
	    admin = Integer.parseInt(g.toString());
	    if(admin == 1)
		{
	    	 showAdminBtn = "inline";
		}
	   
	   
	    System.out.println(" showAdminBtn ==  " + admin);
}
if(session.getAttribute("serverRights") != null)
{
	   
	    Object g =  session.getAttribute("serverRights");
	    server = Integer.parseInt(g.toString());
	    if(server == 1)
		{
	    	showServerBtn = "inline";
		}
	    
	    System.out.println(" showServerBtn ==  " + server);
}


if(session.getAttribute("errorMessage") != null)
  {
    Object g =  session.getAttribute("errorMessage");
    _errorMessage = g.toString();
 }
  else
  {
   _errorMessage = "";
  }
	%>
<%if(session.getAttribute("isCheckedIn") != null)
{ 
		Object g =  session.getAttribute("isCheckedIn");
		int iCk = Integer.parseInt(g.toString());
	
	if(iCk == 1)
	{%>	
	<script type="text/javascript">
		alert("You are checked in already!");
	</script>
	<% 
	session.setAttribute("isCheckedIn",0);
	} 
	
}%>
<div class="landing-page">
	<p class="center-text landing-logo shadow">
    	<img class="replace-2x" width="200" src="../assets/frontera-pesos-logo.png" alt="img">
	      
    </p>
    
    <center>
     
	<div class="tablet-box-expanded" style="width:380px;">
 
      <div class="tablet-customer" style="width:380px;">
        <p>
        <span style="display:<%=showAdminBtn%>">
        <a href="admin-view.jsp">Administration</a> - <a href="admin-view-customer.jsp">Customer Info</a> - 
        <a  href="server.jsp" style="display:<%=showServerBtn%>" >Server</a> -
       
        </span>
        <span> <a href="admin-view-faq.html">Faq</a> - <a href="userHomePage.jsp">Home</a></span>
         </p>
        <span>
        <p><a href="javascript:void(0);" onClick="logUserOut();"><strong>Logout</strong></a><strong></strong></p>
        </span>
        <p>&nbsp;</p>
        <h2>Campaign Rules</h2>
        <p>&nbsp;</p>
        <style type="text/css">
		table{
			border:solid #666 medium;
			margin-left:auto;
			margin-right:auto;
		}
		tr:nth-child(even){background: #FFF;}
		tr:nth-child(odd){background: #EEE;}
		.toprow{
		background-color:#CCC;
		font-size:1.5em;
		}
		
		.td{
			border:1px solid #000;
		}
		
		</style>
		<center>
		<div id="errorTxt" class="errorMessageTxt"><%=_errorMessage %></div>		
       
	  <% if(id != -1)
		  { 
		  	Campaign campaignList = campaignInfo.get(id);
     			%>
     			
        <div style="width:200px; border:solid #666 medium; padding:15px; position:relative;  margin-left:20px; margin-right:18px;">
          <h2>Edit Campaign</h2><br/>
        <form name="addcampaign" id="addcampaign" method="post" action="../Admin">
        <!-- isUpdate // 1 = update 0 = insert
          -->
          	<input type="hidden" name="isUpdate" id="isUpdate" value="1"  />
   			<input type="hidden" name="typeName" id="typeName" value="campaign"  />
   			<input type="hidden" name="adminRequestType" id="adminRequestType" value="addCoupon"  />
   			<input type="hidden" name="aID" id="aID" value="<%=id %>"  />
   			<input type="hidden" name="typeID" id="typeID" value="<%=campaignList.getCampaignId() %>"  />
          <p>
            <label for="campaignname">Campaign Name</label>
            <input name="campaignname"  class="text-input"  id="textfield" type="text" value="<%=campaignList.getCampaignName() %>"  style="background-image:none;" />
  <br/><br/>
            <label for="pesoamount">Pesos Multiplier</label>
            <input name="pesoamount"  class="text-input"  id="textfield" type="text" value="<%=campaignList.getPointMultiplier() %>"  style="background-image:none;" />
            <br/><br/>
            <label for="campaigndatestart">Start Date<br>
              <input name="campaigndatestart" type="date" id="textfield" value="<%=fav.convertDateForHtml(campaignList.getBeginDatetime())%>"  placeholder="mm/dd/yyyy"></label>
            </p>
          <p><br>
            <label for="campaigndateend">End Date<br>
              <input name="campaigndateend" type="date"  id="textfield" value="<%=fav.convertDateForHtml(campaignList.getEndDatetime())%>"  placeholder="mm/dd/yyyy">
              <br>
              <br>
              <br>
              Active upon Submission?</label>
          </p>
         <br/>
              Yes
              <input name="setinitialstatus" type="radio" value="1" <%if(campaignList.getActive()==1){ %>checked<%} %>>
              No
              <input name="setinitialstatus" type="radio" value="0" <%if(campaignList.getActive()==0){ %>checked<%} %> >
              <br/>
              <br/>
               <p>&nbsp;</p>
               <p>Is this a birthday promo?<br/>
                Yes
              <input name="setbirthdaypromo" type="radio" value="1" <%if(campaignList.getBirthdayPromo()==1){ %>checked<%} %>>
              No
              <input name="setbirthdaypromo" type="radio" value="0" <%if(campaignList.getBirthdayPromo()==0){ %>checked<%} %> >
               <p><br/>
              <br/>
            <span class=""><a class="buttonBigYellow" onclick="submitRule('addcampaign')" href="javascript:void(0)">Add Campaign</a></span></p>
        </form>
        </div> 
       <%} %>
        </center>
        
            
        
      </div>
	</div>

    </center>
    

<!--	<p class="login-note shadow"><strong>*</strong>Forgot my Password</p> -->
<div style="height:25px;"></div>
</div>


  
</body>
</html>